//
//  FileHandleExtension.m
//  CocoaMoney
//
//  Created by Daniel Braun on 22/10/06.
//  Copyright 2006 Daniel Braun http://braun.daniel.free.fr. All rights reserved.
//

#import "FileHandleExtension.h"


@implementation NSFileHandle (StringWriting)

- (void) writeString:(NSString *)s
{
	//NSData *d=[s dataUsingEncoding:NSASCIIStringEncoding];
	NSData *d=[s dataUsingEncoding:NSUTF8StringEncoding];
	NSAssert(d, @"data nul");
	[self writeData:d];
}

+ (id) fileHandleForWritingAtPathCreate:(NSString *)fn
{
	NSFileHandle *fh=[[self class] fileHandleForWritingAtPath:fn];
	if (fh) return fh;
	[[NSFileManager defaultManager] createFileAtPath:fn 
						contents:nil
						attributes:[NSDictionary dictionaryWithObjectsAndKeys:
							      NSFileTypeRegular, NSFileType,
							      /*NSFileTypeForHFSTypeCode( ’TEXT’ ), NSFileHFSTypeCode,*/
							      nil]];
	fh=[[self class] fileHandleForWritingAtPath:fn];
	return fh;
}


@end
